package com.jhx.mall.app.servlet;

import com.jhx.mall.app.service.DtsOrderService;
import com.jhx.mall.app.service.impl.DtsOrderServiceImpl;
import com.jhx.mall.util.BaseServlet;
import com.jhx.mall.vo.DtsOrdersVo;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet(name = "DtsOrder", value = "/api/user/myOrder")
public class DtsOrderServlet extends BaseServlet {

    private DtsOrderService dtsOrderService = null;

    @Override
    public void init(ServletConfig config) throws ServletException {
        dtsOrderService = new DtsOrderServiceImpl();
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1、创建out对象
        PrintWriter out = response.getWriter();
        // 2、获取opr请求参数
        String opr = request.getParameter("opr");

        if (opr.equals("list")){
            int userId = Integer.parseInt(request.getParameter("userId"));
            String orderStatus = request.getParameter("orderStatus");
            List<DtsOrdersVo> list = dtsOrderService.selectMyOrder(userId, orderStatus );
            if (list!=null){
                ok(request,response,list);
            }else {
                error(request,response,list);
            }
        } else if (opr.equals("detail")){
            int userId = Integer.parseInt(request.getParameter("userId"));
            List<DtsOrdersVo> list = dtsOrderService.selectOrderDetail(userId);
            if (list!=null){
                ok(request,response,list);
            }else {
                error(request,response,list);
            }
        } else if (opr.equals("quOrder")){
            int id = Integer.parseInt(request.getParameter("id"));
            int i = dtsOrderService.quOrder(id);
            if (i>0){
                ok(request,response,i);
            }else {
                error(request,response,i);
            }
        } else if (opr.equals("delOrder")){
            int id = Integer.parseInt(request.getParameter("id"));
            int i = dtsOrderService.delOrder(id);
            if (i>0){
                ok(request,response,i);
            }else {
                error(request,response,i);
            }
        }

    }
}


























